package math;

/*
 *@description Pow(x, n)
 *@author hkfan
 *@version 1.0
 *@create 2025/6/23 16:50
 */
public class LeetCode_50 {

    public double myPow(double x, int n) {
        return n>=0?quickCal(x,n):quickCal(1.0/x,-n);
    }

    private double quickCal(double x, int n) {
        if (n==0){
            return 1;
        }
        double y = quickCal(x,n/2);
        return n%2==0?y*y:y*y*x;
    }
}
